<?php

class EstadoLogic extends LogicModel {

    public function __construct() {
        parent::__construct(new EstadoDAO());
    }

    public function ajaxListEstadoConsultaCep($params) {
        /* Atributos do objeto que poderam ser ordenado */
        $atributos = array('nome', 'sigla', 'id');
        $order = TDataTableHelper::mountOrderBy($atributos, $params['iSortCol_0'], $params['sSortDir_0']);
        unset($atributos);
        /* Colunas do banco a serem pesquisandas */
        $colunas = array('nom_estado', 'sig_estado', 'cod_estado');
        /* Montar string de pesquisa no where */
        $where = TDataTableHelper::mountSearch($colunas, $params['sSearch'], false);

        unset($colunas);
        /* Total de registros */
        $iTotal = $this->totalRegistro($where);
        /* Listar */
        $arrayListObject = $this->listar($where, $order, null, null, $params['iDisplayStart'], $params['iDisplayLength']);
        unset($where);
        /* Montar output */
        $output = TDataTableHelper::mountArrayOutPut($params['sEcho'], $iTotal);
        unset($iTotal);

        if (isset($arrayListObject[0])) {
            foreach ($arrayListObject as $object) {
                $link = "<a onclick='getPageListMunicipioFromEstado({$object->getId()})' style='cursor:pointer;' >" . $object->getNome() . "</a>";
                $output['aaData'][] = array(
                    utf8_encode($link),
                    utf8_encode($object->getSigla()),
                    utf8_encode($object->getId())
                );
                unset($link);
            }
        }
        unset($arrayListObject);

        return json_encode($output);
    }

}

?>
